package bTree.LeetCode;

public class 零数组变换I {
    public boolean isZeroArray(int[] nums, int[][] queries) {
        int length = nums.length;
        int []diff=new int[length];
        for (int i = 0; i < queries.length; i++) {
            int start = queries[i][0];
            int end = queries[i][1];
            diff[start]++;
            if (end+1<length){
                diff[end+1]--;
            }
        }
        int cur=0;
        for (int i = 0; i < length; i++) {
            cur+=diff[i];
            if (cur<nums[i]){
                return false;
            }
        }
        return true;
    }
}